import { BasicSystem } from "../Basic/BasicSystem";
import { WXAdvertUIConfig, TTAdvertUIConfig } from "../Managers/AdvertManager/AdvertUIConfig";
import EventManager from "../Managers/EventManager";
import { EventTypes } from "../Managers/EventTypes";
import { SDKSystem, PlatformType } from "../SystemSDK/SDKSystem";
import { StorageSystem } from "../SystemStorage/StorageSystem";
import { UIEnum } from "../SystemUI/UIEnum";


export class AdvertSystem extends BasicSystem {

    public static init(d?: any): void {
        if (this.isInit) return;
        this.isInit = true;

        this.onEvents();

        this.isInitFinished = true;
    }

    public static onEvents() {
        EventManager.on(EventTypes.GameEvents.UIChanged, this.onUIChanged, this);

    }

    public static startLv = 0; //限制广告显示的关卡

    public static onUIChanged(ui: UIEnum) {
        if (StorageSystem.getData().levelAssets.curLv <= this.startLv) return;
        //根据当前UI 加载广告数据
        let _cfg;
        switch (SDKSystem._curPlatform) {
            case PlatformType.WXMiniGame:
                _cfg = WXAdvertUIConfig[ui];
                break;
            case PlatformType.PCMiniGame:
            case PlatformType.TTMiniGame:
                _cfg = TTAdvertUIConfig[ui];
                break;
            default:
                break;
        }

        //-------------banner

        if (!!_cfg) {
            if (_cfg.banner) {
                //第一关不显示
                if (StorageSystem.getData().levelAssets.curLv > 1) {
                    EventManager.emit(EventTypes.SDKEvents.ShowBanner);
                }
            } else {
                EventManager.emit(EventTypes.SDKEvents.HideBanner);
            }

            EventManager.emit(EventTypes.UIEvents.ShowTestBanner, _cfg.banner)
        }

    }

}

